package com.cold.demo.rabbitmq.utils;

import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.concurrent.TimeoutException;

public class ConnectionUtils {
    /**
     * 改工具包使用在SendMQ以及Consumer两个类，没有使用交换机
     *
     * @return
     * @throws IOException
     * @throws TimeoutException
     */
    public static Connection getConnection() throws IOException, TimeoutException {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost("192.168.100.34");
        //端口
        factory.setPort(30316);//amqp协议 端口 类似与mysql的3306
        //设置账号信息，用户名、密码、vhost
        factory.setVirtualHost("/");
        factory.setUsername("admin");
        factory.setPassword("p@ssw0rd");
        // 通过工程获取连接
        return factory.newConnection();
    }

    public static void main(String[] args) throws Exception {
        Connection connection = getConnection();

        Channel    channel    = connection.createChannel();

        connection.close();
//        consumeMessage();

    }

    // 消费消息
    private static void consumeMessage() throws Exception{


    }

}

